#!/bin/bash

URL="http://www.isoc.org/worldipv6/participants/participants.xml"
RIPE_URL="http://albatross.ripe.net/6to4relaytest/relays.txt"

# Download the XML
# Filter empty hosts
# Remove the XML tags
# Remove duplicate host names
# Get the first IPv4 and IPv6 addresses for each host (adds consistency for round-robined hosts)
# Remove duplicate addresses
curl -s $URL \
    | grep "v4_only\|v6_only\|hostname" \
    | grep -v "><" \
    | sed "s/ //g; s/<[^>]*>//g" \
    | sort | uniq \
    | perl -pe 'chomp; $_ = `dig +short $_ A|grep -v [g-z] | head -n 1`.`dig +short $_ AAAA|grep -v [g-z] | head -n 1`;' \
    | sort | uniq

curl -s $RIPE_URL \
    | sed "s/#.*//g; s/ .*//g" \
    | grep -v "^[ ]*$" \
    | sort | uniq \
    | perl -pe 'chomp; $_ = `dig +short $_ A|grep -v [g-z] | head -n 1`.`dig +short $_ AAAA|grep -v [g-z] | head -n 1`;' \
    | sort | uniq
